package pong.event;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JList;
import javax.swing.ListModel;

import pong.Main;
import pong.lan.Lan;
import pong.lan.ListItem;

public class DoubleClick extends MouseAdapter{
	
	private JList<ListItem> list;
	
	
	public DoubleClick(JList<ListItem> list){
		this.list = list;
	}
	
	public void mouseClicked(MouseEvent e){
		if(e.getClickCount() == 2){
			synchronized (Lan.lock) {
				int index = list.locationToIndex(e.getPoint());
				@SuppressWarnings("rawtypes")
				ListModel dlm = list.getModel();
				if(index == -1) return;
				ListItem item = (ListItem) dlm.getElementAt(index);
				list.ensureIndexIsVisible(index);
				Main.unirse(item);
			}
			
		}
   }
}
